package com.checkoutcheckins.client.callbacks;

import com.checkoutcheckins.client.data.DataContainer;
import com.checkoutcheckins.client.data.foursquare.Checkin;
import com.checkoutcheckins.client.data.foursquare.FoursquareCheckins;
import com.checkoutcheckins.client.rpc.CheckinResponse;
import com.checkoutcheckins.client.services.FoursquareServiceAsync;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class FoursquareFriendsCheckinsCallback implements
		AsyncCallback<CheckinResponse> {

	private DataContainer dataContainer = null;

	private FoursquareServiceAsync fsSvc = null;

	public FoursquareFriendsCheckinsCallback(FoursquareServiceAsync fsSvc,
			DataContainer dataContainer) {
		this.dataContainer = dataContainer;
		this.fsSvc = fsSvc;
	}

	public void onFailure(Throwable caught) {
		dataContainer.getStatusPanel().showErrorMessage(caught.getMessage(),
				false);
	}

	@Override
	public void onSuccess(CheckinResponse result) {
		
		dataContainer.getStatusPanel().showLoadMessage(result.getMessage(), true);
		
		FoursquareCheckins fsCheckins = new FoursquareCheckins();
		fsCheckins.setCheckins(result.getCheckinList());
		
		for (Checkin checkin : fsCheckins.getGeolocatedCheckins())
		{
			System.out.println(checkin.getUser().getFirstname());
		}

		System.out.println(result.getMessage());
		System.out.println("retrieved size: " + result.getCheckinList().size());
		
		dataContainer.getFoursquareFriendCheckins().setCheckins(
				result.getCheckinList());
		dataContainer.updateFoursquareFriendCheckins();
	}

}
